4e16b3652e3390c5ea678db66b9dee7af767551c,MathTools/src/plugins/Subtract.java,Subtract,run,#,189
Before Change
double constant1 = 0;
double constant2 = 0;
if (args.length <= 0) {
showFeedback("Plugin parameters have not been set.");
return;
}
for (int i = 0; i < args.length; i++) {
if (i == 0) {
inputHeader1 = args[i];
File file = new File(inputHeader1);
image1Bool = file.exists();
if (image1Bool) {
constant1 = -1;
} else {
constant1 = Double.parseDouble(file.getName().replace(".dep", ""));
}
file = null;
} else if (i == 1) {
inputHeader2 = args[i];
File file = new File(inputHeader2);
image2Bool = file.exists();
if (image2Bool) {
constant2 = -1;
} else {
constant2 = Double.parseDouble(file.getName().replace(".dep", ""));
}
file = null;
} else if (i == 2) {
outputHeader = args[i];
}
}
// check to see that the inputHeader and outputHeader are not null.
if ((inputHeader1 == null) || (inputHeader2 == null) || (outputHeader == null)) {
showFeedback("One or more of the input parameters have not been set properly.");
return;
}
try {
int row, col;
double z1, z2;
float progress = 0;
double[] data1;
double[] data2;
if (image1Bool && image2Bool) {
WhiteboxRaster inputFile1 = new WhiteboxRaster(inputHeader1, "r");
WhiteboxRaster inputFile2 = new WhiteboxRaster(inputHeader2, "r");
int rows = inputFile1.getNumberRows();
int cols = inputFile1.getNumberColumns();
double noData = inputFile1.getNoDataValue();
// make sure that the input images have the same dimensions.
if ((inputFile2.getNumberRows() != rows) || (inputFile2.getNumberColumns() != cols)) {
showFeedback("The input images must have the same dimensions and coordinates. Operation cancelled.");
return;
}
WhiteboxRaster outputFile = new WhiteboxRaster(outputHeader, "rw", inputHeader1, WhiteboxRaster.DataType.FLOAT, noData);
outputFile.setPreferredPalette(inputFile1.getPreferredPalette());
for (row = 0; row < rows; row++) {
data1 = inputFile1.getRowValues(row);
data2 = inputFile2.getRowValues(row);
for (col = 0; col < cols; col++) {
z1 = data1[col];
z2 = data2[col];
if ((z1 != noData) && (z2 != noData)) {
outputFile.setValue(row, col, z1 - z2);
}
}
if (cancelOp) {
cancelOperation();
return;
}
progress = (float) (100f * row / (rows - 1));
updateProgress((int) progress);
}
outputFile.addMetadataEntry("Created by the " +
getDescriptiveName() + " tool.");
outputFile.addMetadataEntry("Created on " + new Date());
// close all of the open Whitebox rasters.
inputFile1.close();
inputFile2.close();
outputFile.close();
} else if (image1Bool) {
WhiteboxRaster inputFile1 = new WhiteboxRaster(inputHeader1, "r");
int rows = inputFile1.getNumberRows();
int cols = inputFile1.getNumberColumns();
double noData = inputFile1.getNoDataValue();
WhiteboxRaster outputFile = new WhiteboxRaster(outputHeader, "rw", inputHeader1, WhiteboxRaster.DataType.FLOAT, noData);
outputFile.setPreferredPalette(inputFile1.getPreferredPalette());
for (row = 0; row < rows; row++) {
data1 = inputFile1.getRowValues(row);
for (col = 0; col < cols; col++) {
z1 = data1[col];
if (z1 != noData) {
outputFile.setValue(row, col, z1 - constant2);
}
}
if (cancelOp) {
cancelOperation();
return;
}
progress = (float) (100f * row / (rows - 1));
updateProgress((int) progress);
}
outputFile.addMetadataEntry("Created by the " +
getDescriptiveName() + " tool.");
outputFile.addMetadataEntry("Created on " + new Date());
// close all of the open Whitebox rasters.
inputFile1.close();
outputFile.close();
} else if (image2Bool) {
WhiteboxRaster inputFile2 = new WhiteboxRaster(inputHeader2, "r");
int rows = inputFile2.getNumberRows();
int cols = inputFile2.getNumberColumns();
double noData = inputFile2.getNoDataValue();
WhiteboxRaster outputFile = new WhiteboxRaster(outputHeader, "rw", inputHeader2, WhiteboxRaster.DataType.FLOAT, noData);
outputFile.setPreferredPalette(inputFile2.getPreferredPalette());
for (row = 0; row < rows; row++) {
data2 = inputFile2.getRowValues(row);
for (col = 0; col < cols; col++) {
z2 = data2[col];
if (z2 != noData) {
outputFile.setValue(row, col, constant1 - z2);
}
}
if (cancelOp) {
cancelOperation();
return;
}
progress = (float) (100f * row / (rows - 1));
updateProgress((int) progress);
}
outputFile.addMetadataEntry("Created by the " +
After Change
double constant1 = 0;
double constant2 = 0;
if (args.length < 3) {
showFeedback("Plugin parameters have not been set properly.");
return;
}
String inputHeader1 = args[0];
File file = new File(inputHeader1);
image1Bool = file.exists();
if (image1Bool) {
constant1 = -1;
} else {
constant1 = Double.parseDouble(file.getName().replace(".dep", ""));
}
file = null;
String inputHeader2 = args[1];
file = new File(inputHeader2);
image2Bool = file.exists();
if (image2Bool) {
constant2 = -1;
} else {
constant2 = Double.parseDouble(file.getName().replace(".dep", ""));
}
file = null;
String outputHeader = args[2];
// check to see that the inputHeader and outputHeader are not null.
if ((inputHeader1 == null) || (inputHeader2 == null) || (outputHeader == null)) {
showFeedback("One or more of the input parameters have not been set properly.");
return;
}
try {
int row, col;
double z1, z2;
int progress, oldProgress = -1;
double[] data1;
double[] data2;
if (image1Bool && image2Bool) {
WhiteboxRaster inputFile1 = new WhiteboxRaster(inputHeader1, "r");
WhiteboxRaster inputFile2 = new WhiteboxRaster(inputHeader2, "r");
int rows = inputFile1.getNumberRows();
int cols = inputFile1.getNumberColumns();
double noData1 = inputFile1.getNoDataValue();
double noData2 = inputFile2.getNoDataValue();
// make sure that the input images have the same dimensions.
if ((inputFile2.getNumberRows() != rows) || (inputFile2.getNumberColumns() != cols)) {
showFeedback("The input images must have the same dimensions and coordinates. Operation cancelled.");
return;
}
WhiteboxRaster outputFile = new WhiteboxRaster(outputHeader, "rw",
inputHeader1, WhiteboxRaster.DataType.FLOAT, noData1);
outputFile.setPreferredPalette(inputFile1.getPreferredPalette());
for (row = 0; row < rows; row++) {
data1 = inputFile1.getRowValues(row);
data2 = inputFile2.getRowValues(row);
for (col = 0; col < cols; col++) {
z1 = data1[col];
z2 = data2[col];
if ((z1 != noData1) && (z2 != noData2)) {
outputFile.setValue(row, col, z1 - z2);
} else {
outputFile.setValue(row, col, noData1);
}
}
progress = (int) (100f * row / (rows - 1));
if (progress != oldProgress) {
oldProgress = progress;
updateProgress((int) progress);
if (cancelOp) {
cancelOperation();
return;
}
}
}
outputFile.addMetadataEntry("Created by the "
+ getDescriptiveName() + " tool.");
outputFile.addMetadataEntry("Created on " + new Date());
// close all of the open Whitebox rasters.
inputFile1.close();
inputFile2.close();
outputFile.close();
} else if (image1Bool) {
WhiteboxRaster inputFile1 = new WhiteboxRaster(inputHeader1, "r");
int rows = inputFile1.getNumberRows();
int cols = inputFile1.getNumberColumns();
double noData = inputFile1.getNoDataValue();
WhiteboxRaster outputFile = new WhiteboxRaster(outputHeader, "rw", inputHeader1, WhiteboxRaster.DataType.FLOAT, noData);
outputFile.setPreferredPalette(inputFile1.getPreferredPalette());
for (row = 0; row < rows; row++) {
data1 = inputFile1.getRowValues(row);
for (col = 0; col < cols; col++) {
z1 = data1[col];
if (z1 != noData) {
outputFile.setValue(row, col, z1 - constant2);
}
}
progress = (int) (100f * row / (rows - 1));
if (progress != oldProgress) {
oldProgress = progress;
updateProgress((int) progress);
if (cancelOp) {
cancelOperation();
return;
}
}
}
outputFile.addMetadataEntry("Created by the "
+ getDescriptiveName() + " tool.");
outputFile.addMetadataEntry("Created on " + new Date());
// close all of the open Whitebox rasters.
inputFile1.close();
outputFile.close();
} else if (image2Bool) {
WhiteboxRaster inputFile2 = new WhiteboxRaster(inputHeader2, "r");
int rows = inputFile2.getNumberRows();
int cols = inputFile2.getNumberColumns();
double noData = inputFile2.getNoDataValue();
WhiteboxRaster outputFile = new WhiteboxRaster(outputHeader, "rw", inputHeader2, WhiteboxRaster.DataType.FLOAT, noData);
outputFile.setPreferredPalette(inputFile2.getPreferredPalette());
for (row = 0; row < rows; row++) {
data2 = inputFile2.getRowValues(row);
for (col = 0; col < cols; col++) {
z2 = data2[col];
if (z2 != noData) {
outputFile.setValue(row, col, constant1 - z2);
}
}
progress = (int) (100f * row / (rows - 1));
if (progress != oldProgress) {
oldProgress = progress;
updateProgress((int) progress);
if (cancelOp) {
cancelOperation();
return;
}